var jqGrid_template = {
		datatype : "local",
		height : 'auto',
		sortname : 'name',
		sortorder : "asc",
		multiselect:true,
		autowidth : true,
		pager : '#pjqgrid',
		hidegrid: false,
		rowNum: 20,
        rowList: [10, 20, 30],
        emptyrecords: "Nothing to display",
        viewrecords: true
}

function jqGrid_LoadComplete(){
	$("#jqgrid").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
}

function jqGrid_OnSelectRow(id){
    var s;
    s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow');
    if(s.length>1){
        for(var i=0;i<=s.length;i++){
            if(s[i]!=id){
                $("#jqgrid").jqGrid('setSelection', s[i]);
            }
        }
    }
}

function jqGrid_OnSelectAll(rowids, statue) {
    $("#jqgrid").jqGrid('resetSelection');
}

function jqGrid_ResetClass(){
	$("#jqgrid").navGrid('#pjqgrid',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgrid").jqGrid( 'setGridWidth', $("#content").width() );
    })
}

function monitorStatus(status){
	switch(status){
	case 'passing':
		return '<span class=\"label label-success\">'+status+'</spam>';
	case 'critcal':
		return '<span class=\"label label-danger\">'+status+'</spam>';
	default:
		return status;
	}
}

//新建备份存储列表 
function createGrid_bs(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '名称', '类型', 'IP地址', '源目录', '挂载目录', '挂载参数', '空闲容量','总容量','启用/停用','id','createDateTime','createLoginUserName'];
	option.colModel = [
        { name : 'name', index : 'name', editable : false,width:'180px' },
        { name : 'type', index : 'type', editable : true },
        { name : 'ip', index : 'ip',editable : false },
        { name : 'dir', index : 'dir',editable : false },
        { name : 'mountDir', index : 'mountDir', editable : false },
        { name : 'mountOpts', index : 'mountOpts',  editable : false },
        { name : 'freeSpace', index : 'freeSpace', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
      		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
            }
        },
        { name : 'totalSpace', index : 'totalSpace' /*sortable : false, editable : true */,
        	formatter: function (cellvalue, options, rowObject) {
      		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
            }
        },
        { name : 'enabled', index : 'enabled' ,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
                if (cellvalue == true) return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";},
            sortable : false/*,align:"left"*/},
        {name:"id",index:"id",hidden:true},
        {name:"createDateTime ",index:"createDateTime ",hidden:true},
        {name:"createLoginUserName",index:"createLoginUserName",hidden:true}            
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//区域列表
function createGrid_area(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '区域名称', '区域描述', '备份存储', '启用/停用','enabledStatus','id','backupStorageId','createDateTime','createLoginUserName'];
	option.colModel = [
        { name : 'name', index : 'name', editable : false},
        { name : 'description', index : 'description', editable : false },
        { name : 'backupStorageName', index : 'backupStorageName', editable : false },
        { name : 'enabled', index : 'enabled' ,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
                if (cellvalue == true) return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";},
            sortable : false},
        { name : 'enabledStatus', index : 'enabledStatus' ,
                formatter: function (cellvalue, options, rowObject) {
                    if (rowObject.enabled == false) return "yes";
                    if (rowObject.enabled == true) return "no";},
                    hidden:true},
        {name:"id",index:"id",hidden:true},
        {name:"backupStorageId ",index:"backupStorageId ",hidden:true},
        {name:"createDateTime ",index:"createDateTime ",hidden:true},
        {name:"createLoginUserName",index:"createLoginUserName",hidden:true} 
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//集群列表
function createGrid_cluster(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '所属区域', '网络标签', '集群名称', '最大使用率(%)','最大主机数量','包含软件', '包含网段', '混合类型', '启用/停用','enabledStatus','id'];
	option.colModel = [
        { name : 'areaName', index : 'areaName', editable : false },
        { name : 'haNetworkTag', index : 'haNetworkTag', editable : false },
        { name : 'name', index : 'name', editable : false },
        { name : 'maxUsage', index : 'maxUsage', editable : false },
        { name : 'maxHostCount', index : 'maxHostCount', editable : false },
        { name : 'definitionSubServNames', index : 'definitionSubServNames', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if(cellvalue.length == 0){
        			return "";
        		} else {
        			var ret = "";
        			$.each(cellvalue, function(k, v){
        				ret = ret + v.name + "<br/>";
        			});
        			return ret;
        		}
        	}
        },
        { name : 'networkings', index : 'networkings', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if(cellvalue.length == 0){
        			return "";
        		} else {
        			var ret = "";
        			$.each(cellvalue, function(k, v){
        				ret = ret + v.name + "<br/>";
        			});
        			return ret;
        		}
        	}
        },
        { name : 'mixed', index : 'mixed' ,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "非混合";
                if (cellvalue == true) return "混合";},
            sortable : false},
        { name : 'enabled', index : 'enabled' ,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
                if (cellvalue == true) return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";},
            sortable : false},
        { name : 'enabledStatus', index : 'enabledStatus' ,
                formatter: function (cellvalue, options, rowObject) {
                    if (rowObject.enabled == false) return "yes";
                    if (rowObject.enabled == true) return "no";},
                    hidden:true},
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//网段列表
function createGrid_net(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = ['网段名称', '起始IP','结束IP','掩码','网关', '所用区域','所用集群','标记vlanID','启用/停用','enabledStatus','id'];
	option.colModel = [
        { name : 'name', index : 'name', editable : false, },
        { name : 'startIp', index : 'startIp', editable : false },
        { name : 'endIp', index : 'endIp', editable : false },
        { name : 'prefix', index : 'prefix', editable : false },
        { name : 'gateway', index : 'gateway', editable : false },
        { name : 'areaName', index : 'areaName',  editable : false },
        { name : 'clusterName', index : 'clusterName',  editable : false },
        { name : 'vlanId', index : 'vlanId',  editable : false },
        { name : 'enabled', index : 'enabled' ,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
                if (cellvalue == true) return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";},
           sortable : false},
        { name : 'enabledStatus', index : 'enabledStatus' ,
               formatter: function (cellvalue, options, rowObject) {
                   if (rowObject.enabled == false) return "yes";
                   if (rowObject.enabled == true) return "no";},
                   hidden:true},
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();    
}

//软件镜像列表
function createGrid_si_1(data) {
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '软件名称', '版本', '启用/停用', '状态', '任务详情','id' ];
	option.colModel = [
		{
			name : 'name',
			index : 'name',
			editable : false
		},
		{
			name : 'majorVersion',
			index : 'majorVersion',
			editable : false,
			formatter : function(cellvalue,
					options, rowObject) {
				return rowObject.majorVersion 
						+ "." 
						+ rowObject.minorVersion 
						+ "."
						+ rowObject.patchVersion 
						+ "." 
						+ rowObject.buildVersion;
			},
			
			sortable : false
		},
		{
			name : 'enabled',
			index : 'enabled',
			formatter : function(cellvalue,
					options, rowObject) {
				if (cellvalue == false)
					return "<span class=\"txt-color-red pull-left\">"
							+ "<i class=\"fa fa-lg fa-times\"></i></span>";
				if (cellvalue == true)
					return "<span class=\"txt-color-green pull-left\">"
							+ "<i class=\"fa fa-lg fa-check\"></i></span>";
			},
			
			sortable : false
		},
		{
			name : 'taskStatusText',index : 'taskStatusText',editable : false
		},
		{
			name : 'info',
			index : "1",
			formatter : function(cellvalue,
					options, rowObject) {
				return "<a href=\"\" data-task-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
			},
			editable : false
		},
		{name:"id",index:"id",hidden:true}
		];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

function createGrid_si_2(data) {
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '软件名称', '图标', '主版本', '次版本','id'];
	option.colModel = [ {
		name : 'id',
		index : 'id',
		editable : false
	}, {
		name : 'icon',
		index : 'icon',
		formatter : function(cellvalue, options, rowObject) {
			if (cellvalue == '1')
				return "<i class=\"fa fa-qq\"></i>";
			if (cellvalue == '2')
				return "<i class=\"fa fa-wechat\"></i>";
			if (cellvalue == '3')
				return "<i class=\"fa fa-paw\"></i>";
		},
		sortable : false,width : '60px',
	}, {
		name : 'majorVersion',
		index : 'majorVersion',
		align : "center",
		editable : false
	}, {
		name : 'minorVersion',
		index : 'minorVersion',
		align : "center",
		editable : false
	},
	{name:"id",index:"id",hidden:true}
	];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


//主机列表
function createGrid_host_1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '主机名称', '主机IP', '所属区域','所属集群','机房','机位','容器上限','status','主机状态','最新任务状态','任务详情','id'];
	option.colModel = [
        { name : 'name', index : 'name', editable : false },
        { name : 'sshIp', index : 'sshIp', editable : false,width:'180px' },
        { name : 'areaName', index : 'areaName', editable : false },
        { name : 'clusterName', index : 'clusterName', editable : false },
        { name : 'room', index : 'room', editable : false },
        { name : 'seat', index : 'seat', editable : false },
        { name : 'maxContainer', index : 'maxContainer', editable : false},
        { name : 'status', index : 'status', hidden:true},
        { name : 'statusText', index : 'statusText', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if(rowObject.status == "enable"){
        			return "<span style='color:green;font-weight: bold;'>"+cellvalue+"</span>";
        		}else if(rowObject.status == "disable"){
        			return "<span style='color:red;font-weight: bold;'>"+cellvalue+"</span>";
        		}else{
        			return "<span style='color:blue;font-weight: bold;'>"+cellvalue+"</span>";
        		}
            }
        },
        { name : 'taskStatusText', index : 'taskStatusText', editable : false},
        { name : 'detail', index : 'detail', align : "center", editable : false,
            formatter: function (cellvalue, options, rowObject) {
                return "<a href=\"\" data-task-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
            },
             editable: false, align: "center"},
        {
           name : 'id', index : 'id',hidden:true
        }
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

function createGrid_taskDetail(data){
    $.each(data.data,function(index,obj){
    	$("#mainframestate").append(
                "<tr><td>"
        		+obj['objId']+"</td> <td>"
        		+obj['startDateTime']+"</td> <td>"
        		+obj['endDateTime']+"</td> <td>"
        		+obj['objType']+"</td> <td>"
        		+obj['objName']+"</td> <td>"
        		+obj['actionType']+"</td> <td>"
        		+obj['statusText']+"</td> <td>"
        		+obj['msg']+"</td></tr>"
        );
    });
}

//SANS列表
function createGrid_san_1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '存储名称', '所属站点', '品牌','总量','剩余容量','登记时间 ','id'];
	option.colModel = [
      { name : 'name', index : 'name', editable : false },
      { name : 'siteName', index : 'siteName', editable : false,width:'180px' },
      { name : 'vendor', index : 'vendor', editable : false,
          formatter: function (cellvalue, options, rowObject) {
        	  return cellvalue.code;
          }
      },
      { name : 'total', index : 'total', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
    		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
          },
      },
      { name : 'free', index : 'free', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
    		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
          },
      },
      { name : 'createDateTime', index : 'createDateTime', editable : false },
      {
          name : 'id', index : 'id',hidden:true
       }
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


//RG列表
function createGrid_rg(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ 'RG编号', '总量', '剩余容量','lun总数','状态'];
	option.colModel = [
      { name : 'number', index : 'number', editable : false },
      { name : 'total', index : 'total', editable : false,width:'180px',
    	  formatter: function (cellvalue, options, rowObject) {
    		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
          },    
      },
      { name : 'free', index : 'free', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
    		  return (cellvalue/1024/1024/1024).toFixed(1)+"G";
          },   
      },
      { name : 'lunNum', index : 'lunNum', editable : false },
      { name : 'enabled', index : 'enabled', editable : false ,
    	  formatter: function (cellvalue, options, rowObject) {
    		  if(cellvalue){
    			  return "启用";
    		  }else{
    			  return "停用";
    		  }
          },  
      }
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//端口列表
function createGrid_port(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '端口', '所属服务','启用状态', '分配状态','id'];
	option.colModel = [
        { name : 'portValue', index : 'portValue', editable : false},
        { name : 'servName', index : 'servName',  editable : false },
        { name : 'enabledText', index : 'enabledText',  editable : false },
        { name : 'used', index : 'used' , editable : false,
            formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == false) return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
                if (cellvalue == true) return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";},
            sortable : false, search:false
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//UPSQL工单列表
function createGrid_wo_1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '站点', '区域', '系统', '子系统', '用户', '服务名称','服务类型', '创建时间','状态','id'];
	option.colModel = [
        { name : 'siteName', index : 'siteName', editable : false },
        { name : 'areaName', index : 'areaName', editable : false },
        { name : 'businessSystemName', index : 'businessSystemName', editable : false },
        { name : 'businessSubSystemName', index : 'businessSubSystemName',  editable : false },
        { name : 'owner', index : 'owner',  editable : false },
        { name : 'servName', index : 'servName',  editable : false },
        { name : 'servTypeName', index : 'servTypeName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
                if (cellvalue == 'upredis_urproxy_sentinel') return "UPREDIS";
                if (cellvalue == 'upsql_upproxy_swm') return "UPSQL";
            },
        },
        { name : 'createDateTime', index : 'createDateTime', editable : false},
        { name : 'statusText', index : 'statusText', editable : false},
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//REDIS工单列表
function createGrid_wo_2(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '站点', '区域', '系统', '子系统', '用户', '服务名称', '创建时间','状态','id'];
	option.colModel = [
        { name : 'siteName', index : 'siteName', editable : false },
        { name : 'areaName', index : 'areaName', editable : false },
        { name : 'businessSystemName', index : 'businessSystemName', editable : false },
        { name : 'businessSubSystemName', index : 'businessSubSystemName',  editable : false },
        { name : 'owner', index : 'owner',  editable : false },
        { name : 'servName', index : 'servName',  editable : false },
        { name : 'createDateTime', index : 'createDateTime', editable : false},
        { name : 'statusText', index : 'statusText', editable : false},
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//主机资源监控
function createGridMonitorHostResource(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = [ '主机名', '所属站点', '所属区域', '所属集群', '网络地址', '状态', '分配值/总值', '状态', '分配值/总值', '状态', '分配值/总值', '状态', '分配值/总值', '主机状态', '监控'];
	option.colModel = [
        { name: 'name', index: 'name', editable: false },
        { name: 'siteName', index: 'siteName', editable: false },
        { name: 'areaName', index: 'areaName', editable: false },
        { name: 'clusterName', index: 'clusterName',  editable: false },
        { name: 'sshIp', index: 'sshIp',  editable: false },
        { name : 'cpuStatus', index : 'cpuStatus', editable : false,
            formatter: function (cellvalue, options, rowObject) {
            	if (LimitCheck(rowObject.usedCpuCnt, rowObject.cpuCnt)) {
            		return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";
            	} else{
            		return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
            	}
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name: 'cpuResource', index: 'cpuResource', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	return rowObject.usedCpuCnt + '/' + rowObject.cpuCnt;
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name : 'memStatus', index : 'memStatus', editable : false,
            formatter: function (cellvalue, options, rowObject) {
            	if (LimitCheck(rowObject.usedMemCnt, rowObject.memCnt)) {
            		return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";
            	} else{
            		return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
            	}
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name: 'memResource', index: 'memResource', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	return BytesToGB(rowObject.usedMemCnt) + '/' + BytesToGB(rowObject.memCnt);
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name : 'hddStatus', index : 'hddStatus', editable : false,
            formatter: function (cellvalue, options, rowObject) {
            	if (LimitCheck(rowObject.usedHddCnt, rowObject.hddCnt)) {
            		return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";
            	} else{
            		return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
            	}
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name: 'hddResource', index: 'hddResource', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	return BytesToGB(rowObject.usedHddCnt) + '/' + BytesToGB(rowObject.hddCnt);
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name : 'ssdStatus', index : 'ssdStatus', editable : false,
            formatter: function (cellvalue, options, rowObject) {
            	if (LimitCheck(rowObject.usedSsdCnt, rowObject.ssdCnt)) {
            		return "<span class=\"txt-color-green pull-left\"><i class=\"fa fa-lg fa-check\"></i></span>";
            	} else{
            		return "<span class=\"txt-color-red pull-left\"><i class=\"fa fa-lg fa-times\"></i></span>";
            	}
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name: 'ssdResource', index: 'ssd	Resource', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	return BytesToGB(rowObject.usedSsdCnt) + '/' + BytesToGB(rowObject.ssdCnt);
            },
            sorttype: function (cell, rowObject) {
                return rowObject.usedCpuCnt/rowObject.cpuCnt;
            }
        },
        { name: 'statusText', index: 'statusText',  editable: false },
        { name : 'monitor', index : 'monitor', editable : false,
            formatter: function (cellvalue, options, rowObject) {
            	return "<a href=\"javascript:void(0)\" onclick=\"forwardHostResourceDetail('"+rowObject.id+"','"+rowObject.statusText+"')\"><span class=\"pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        }
    ];
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	$('#jqgrid').setGroupHeaders(
		{
			useColSpanStyle: true,
			groupHeaders: [
				{ numberOfColumns: 2, titleText: "CPU使用率", startColumnName: "cpuStatus" },
				{ numberOfColumns: 2, titleText: "内存使用率", startColumnName: "memStatus" },
				{ numberOfColumns: 2, titleText: "HDD使用率", startColumnName: "hddStatus" },
				{ numberOfColumns: 2, titleText: "SSD使用率", startColumnName: "ssdStatus" }
			]
		});
	
	jqGrid_ResetClass();
}

//组件监控
function createGridComponent(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = [ '组件名称', '组件状态', '组件IP地址', '组件端口号'];
	option.colModel = [
        { name : 'name', index : 'name', editable : false },
        { name : 'Status', index : 'Status', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
            	return monitorStatus(rowObject.Status);
            }
        },
        { name : 'Ip', index : 'Ip', editable : false },
        { name : 'port', index : 'port',  editable : false }
    ];
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//主机状态监控
function createGridHostStatus(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = [ '主机名', '所属集群', '运行状态', '管理agent状态', 'docker状态', 'docker plugin状态', '实例单元信息'];
	option.colModel = [
        { name : 'host_name', index : 'host_name', editable : false },
        { name : 'cluster_name', index : 'cluster_name', editable : false },
        { name : 'host_status', index : 'host_status', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
            	return monitorStatus(rowObject.host_status);
            }
        },
        { name : 'swarm_agent_status', index : 'swarm_agent_status',  editable : false,
        	formatter: function (cellvalue, options, rowObject) {
            	return monitorStatus(rowObject.swarm_agent_status);
            }
        },
        { name : 'docker_status', index : 'docker_status',  editable : false,
        	formatter: function (cellvalue, options, rowObject) {
            	return monitorStatus(rowObject.docker_status);
            }
        },
        { name : 'docker_plugin_status', index : 'docker_plugin_status',  editable : false,
        	formatter: function (cellvalue, options, rowObject) {
            	return monitorStatus(rowObject.docker_plugin_status);
            }
        },
        { name : 'detail', index : 'detail', editable : false,
            formatter: function (cellvalue, options, rowObject) {
                return "<a href=\"\" data-unit-id='"+rowObject.host_id+"'\" data-toggle=\"modal\" data-target=\"#unitModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        }
    ];
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//任务监控
function createGridTask(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = [ '任务类型', '任务结果', '实例名称', '操作者', '开始时间', '结束时间', '总耗时'];
	option.colModel = [
        { name : 'actionType', index : 'actionType', editable : false },
        { name : 'statusText', index : 'statusText', editable : false },
        { name : 'objName', index : 'objName', editable : false },
        { name : 'owner', index : 'owner',  editable : false },
        { name : 'startDateTime', index : 'startDateTime',  editable : false },
        { name : 'endDateTime', index : 'endDateTime',  editable : false },
        { name : 'duration', index : 'duration',  editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var startDateTime = new Date(rowObject.startDateTime);
        		var endDateTime = new Date(rowObject.endDateTime);
        		var duration = Math.round((endDateTime.getTime() - startDateTime.getTime())/1000);
        		var hour = Math.round(duration / 3600) > 0 ? Math.round(duration / 3600) + '小时' : '';
        		var minute = Math.round((duration % 3600) / 60) > 0 ? Math.round((duration % 3600) / 60) + '分钟' : '';
        		var second = (duration % 60) + '秒';
        		return hour + minute + second;
            }
        }
    ];
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//实例监控
function createGridInstance(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = [ '所属用户', '业务名', '子业务名', '实例名', '实例状态', '实例单元信息'];
	option.colModel = [
        { name : 'owner', index : 'owner', editable : false },
        { name : 'businessSystemName', index : 'businessSystemName', editable : false },
        { name : 'businessSubSystemName', index : 'businessSubSystemName', editable : false },
        { name : 'servName', index : 'servName',  editable : false },
        { name : 'statusText', index : 'statusText',  editable : false },
        { name : 'detail', index : 'detail',  editable : false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<a href=\"\" data-unit-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#unitModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        }
    ];
	option.grouping = true;
	option.groupingView = {
			groupField: ["owner", "businessSystemName", "businessSubSystemName"],
            groupColumnShow: [true, true, true],
            groupText: [
				"所属用户: <b>{0}</b>",
				"业务名: <b>{0}</b>",
				"子业务名: <b>{0}</b>"
			],
            groupOrder: ["asc", "asc", "asc"],
            groupSummary: [false, false, false],
			groupSummaryPos: ['header', 'header', 'header'],
            groupCollapse: false
	};
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

function createGridUnitDetail(data){
    $.each(data.data, function(index,obj){
    	$("#mainframestate").append(
                "<tr><td>"
        		+obj['container_name']+"</td> <td>"
        		+obj['unit_type']+"</td> <td>"
        		+obj['container_status']+"</td></tr>"
        );
    });
}


//新建redis服务列表
function createGrid_redis_1(data){
	$("#jqgrid").jqGrid({
        data : data['data'],
        datatype : "local",
        height : 'auto',
        colNames : [ '服务名', '所属用户', '状态','任务详情', '任务状态', 'id'],
        colModel : [
            { name : 'servName', index : 'servName', editable : false },
            { name : 'owner', index : 'owner', editable : false },
            { name : 'statusText', index : 'statusText', editable : false},
            { name : 'taskStatusText', index : 'taskStatusText', editable : false},
            {
                name: 'info', index : 'info', editable: false,
                formatter: function (cellvalue, options, rowObject) {
                    return "<a href=\"\" data-toggle=\"modal\" data-target=\"#myModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
                },
            },
            {name:"id",index:"id",hidden:true}
        ],
        //pager : '#pjqgrid',
        sortname : 'name',
        sortorder : "asc",
        multiselect:true,//设置为false则无勾选框出现
        hidegrid:false,
        editurl : "dummy.html",
        caption : "",
        autowidth : true,
        loadComplete: function () {  //隐藏滚动条
            $("#jqgrid").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
        },
        onSelectRow: function(id){
            var s;
            s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow');
            if(s.length>1){
                for(var i=0;i<=s.length;i++){
                    if(s[i]!=id){
                        $("#jqgrid").jqGrid('setSelection', s[i]);
                    }
                }
            }
        },
        onSelectAll:function(rowids,statue) {
            $("#jqgrid").jqGrid('resetSelection');
        }

    });
    $("#jqgrid").jqGrid('navGrid', "#pjqgrid", {
        edit : false,
        add : false,
        del : true
    });
    $("#jqgrid").jqGrid('inlineNav', "#pjqgrid");
    /* Add tooltips */
    $('.navtable .ui-pg-button').tooltip({
        container : 'body'
    });
    /* Add tooltips */
    $('.navtable .ui-pg-button').tooltip({
        container : 'body'
    });

    // remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");

    $(window).on('resize.jqGrid', function () {
        $("#jqgrid").jqGrid( 'setGridWidth', $("#content").width() );
    })
}
function createGrid_redis_2(data){
	 var stateTable=$("#mainframestate");
     $.each(data,function(index,obj){
         stateTable.append(
                 "<tr><td>"+obj['name']+"</td> <td>" +obj['time']+"</td> <td>" +
                 obj['type']+"</td> <td>" +obj['objectname']+"</td> <td>" +
                 obj['type2']+"</td> <td>" +obj['state']+"</td> <td>" +
                 obj['return']+
                 "</td> </tr>"
         );
     });
}
//新建redis服务管理列表
function createGrid_redis_m1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = ['单元名称', '所属集群', '所属主机', 'IP地址', '端口','cpu数量','内存','数据容量', '日志容量', '状态','容器状态','任务详情','id'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false},
        {name: 'clusterName', index: 'clusterName', editable: false},
        {name: 'hostName', index: 'hostName',  editable: false},
        {name: 'hostIp', index: 'hostIp',  editable: false},
        {name: 'portValue', index: 'portValue',  editable: false},
        {name: 'cpuCount', index: 'cpuCount', editable: false},
        {name: 'memSize', index: 'memSize',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return BytesToSize(rowObject.memSize);
            }
        },
        {name: 'dataDirSize', index: 'dataDirSize',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return BytesToSize(rowObject.dataDirSize);
            }
        },
        {name: 'logDirSize', index: 'logDirSize',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return BytesToSize(rowObject.logDirSize);
            }
        },
        {name: 'statusText', index: 'statusText',  editable: false},
        {name: 'containerStatus', index: 'containerStatus', editable: false},
        {
            name: 'info', index: 'info', editable: false,
            formatter: function (cellvalue, options, rowObject) {
                return "<a href=\"\" data-toggle=\"modal\" data-target=\"#myModal\"><span class=\" pull-left\"><i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.grouping = true;
	option.groupingView = {
			groupField: ["portValue"],
            groupColumnShow: [true],
            groupText: [
				"分片号: <b>{0}</b>"
			],
            groupOrder: ["asc"],
            groupSummary: [false],
			groupSummaryPos: ['header'],
            groupCollapse: false
	};
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}
function createGrid_redis_m2(data){
	 var stateTable = $("#mainframestate");
    $.each(data, function (index, obj) {
        stateTable.append(
                "<tr><td>" + obj['name'] + "</td> <td>" + obj['time'] + "</td> <td>" +
                obj['type'] + "</td> <td>" + obj['objectname'] + "</td> <td>" +
                obj['type2'] + "</td> <td>" + obj['state'] + "</td> <td>" +
                obj['return'] +
                "</td> </tr>"
        );
    });
}
function createGrid_redis_m3(data){
	 $.each(data, function (index, obj) {
        $("#name").append(obj['name']);
        $("#owner").append(obj['owner']);
        $("#architecture").append(obj['architecture']);
        $("#scale").append(obj['scale']);
        $("#software").append(obj['software']);
        $("#state").append(obj['state']);
    });
}

//upsql服务列表
function createGrid_mysql_1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames =  [ '站点名称','所属用户','业务系统','业务子系统','服务名称','部署架构','软件版本', '性能套餐','访问地址','服务状态','任务状态','softwareImageId','dateSize','networkBandwidth','id'];
	option.colModel = [
		{ name : 'siteName', index : 'siteName', editable : false },
		{ name : 'owner', index : 'owner', editable : false },
		{ name : 'businessSystemName', index : 'businessSystemName', editable : false },
		{ name : 'businessSubSystemName', index : 'businessSubSystemName', editable : false },
        { name : 'servName', index : 'servName', editable : false },
        { name : 'archName', index : 'archName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.archName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'softwareVersion', index : 'softwareVersion', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.softwareVersion;
        			}
        		});
        		return ret;
            }
        },
        { name : 'scaleName', index : 'scaleName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.scaleName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'endPointIps', index : 'endPointIps', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upproxy' && v.endPointIps != undefined){
        				$.each(v.endPointIps, function(i, endPointIp){
        					ret += endPointIp +":"+v.port+ "</br>";
            			});
        			}
        		});
        		return ret;
            }
        },
        { name : 'availableStatus', index : 'availableStatus', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing'){ return "<span class=\"txt-color-green pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";}else
                if (cellvalue == 'warning'){ return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";}
                if (cellvalue == 'critical'){ return "<span class=\"txt-color-red pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";}else
                if (cellvalue == 'unknown'){ return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";}else
                	{return "";}
        	}
        },
        { name : 'taskStatusText', index : 'taskStatusText', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-service-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#serviceModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            },editable: false, align: "center"
        },
        { name : 'softwareImageId', index : 'softwareImageId', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.softwareImageId;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'dateSize', index : 'dateSize', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.dateSize;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'networkBandwidth', index : 'networkBandwidth', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				if(v.networkBandwidth == 0){
        					ret = "无限制";
        				}else{
        					ret = v.networkBandwidth+"M";
        				}
        			}
        		});
        		return ret;
            },hidden:true
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}
function createGrid_serviceDetail(data){
	var stateTable=$("#mainframestate");
    $.each(data.data ,function(index,obj){
        stateTable.append(
                "<tr><td>"+obj['owner']+"</td> <td>" +obj['startDateTime']+"</td> <td>" +
                obj['objType']+"</td> <td>" +obj['objName']+"</td> <td>" +
                obj['actionType']+"</td> <td>" +obj['statusText']+"</td> <td>" +
                obj['msg']+
                "</td> </tr>"
        );
    });
}
//新建mysql服务管理列表
function createGrid_mysql_m1(data){
	var option = {};
	var colornum = '';
	var dataArray=new Array();
	for(var i=0;i<data['data'].length;i++){
		(i%2 ==0) ?colornum = "333333":colornum = "900323";
		for(var k=0;k<data['data'][i]['units'].length;k++){
			data['data'][i]['units'][k]['fontcolor'] = colornum;
			dataArray.push(data['data'][i]['units'][k]);
		}
	}
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = dataArray; 
	option.colNames = ['实例单元名称', '所属集群', '所属主机', '服务地址', '服务端口','版本号','角色', '容器状态', '运行状态','可用状态','任务详情', 'id'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            },width:'200px'
        },
        {name: 'clusterName', index: 'clusterName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'hostName', index: 'hostName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'serverIp', index: 'serverIp', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'portValue', index: 'portValue', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'softwareVersion', index: 'softwareVersion',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'role', index: 'role', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'containerStatus', index: 'containerStatus', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'status', index: 'status',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing') return "<span class=\"txt-color-green pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";
                if (cellvalue == 'warning') return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";
                if (cellvalue == 'critical') return "<span class=\"txt-color-red pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";
                if (cellvalue == 'unknown') return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";
            }
        },
        {name: 'availableStatus', index: 'availableStatus',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'normal') return "<span class=\"txt-color-green pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";
                if (cellvalue == 'warning') return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";
                if (cellvalue == 'abnormal') return "<span class=\"txt-color-red pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";
                if (cellvalue == 'unknown') return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";
            }
        },
        {
            name: 'taskStatusText', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-upsql-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


//新建upproxy服务管理列表
function createGrid_upproxy(data){
	var option = {};
	var colornum = '';
	var dataArray=new Array();
	for(var i=0;i<data['data'].length;i++){
		(i%2 ==0) ?colornum = "333333":colornum = "900323";
		for(var k=0;k<data['data'][i]['units'].length;k++){
			data['data'][i]['units'][k]['fontcolor'] = colornum;
			dataArray.push(data['data'][i]['units'][k]);
		}
	}
	
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = dataArray;
	option.colNames = ['实例单元名称', '所属集群', '所属主机', '服务地址', '服务端口','版本号', '容器状态', '运行状态','任务详情', 'id'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'clusterName', index: 'clusterName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'hostName', index: 'hostName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'serverIp', index: 'serverIp', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'portValue', index: 'portValue', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'softwareVersion', index: 'softwareVersion',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'containerStatus', index: 'containerStatus', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'status', index: 'status',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing') return "<span class=\"txt-color-green pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";
                if (cellvalue == 'warning') return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";
                if (cellvalue == 'critical') return "<span class=\"txt-color-red pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";
                if (cellvalue == 'unknown') return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";
            }
        },
        {
            name: 'taskStatusText', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-upsql-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


//新建switch_manager服务管理列表
function createGrid_switch_manager(data){
	var option = {};
	var colornum = '';
	var dataArray=new Array();
	for(var i=0;i<data['data'].length;i++){
		(i%2 ==0) ?colornum = "333333":colornum = "900323";
		for(var k=0;k<data['data'][i]['units'].length;k++){
			data['data'][i]['units'][k]['fontcolor'] = colornum;
			dataArray.push(data['data'][i]['units'][k]);
		}
	}
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = dataArray;
	option.colNames = ['实例单元名称', '所属集群', '所属主机', '服务地址', '服务端口','版本号', '容器状态', '运行状态','任务详情', 'id'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'clusterName', index: 'clusterName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'hostName', index: 'hostName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'serverIp', index: 'serverIp', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'portValue', index: 'portValue', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'softwareVersion', index: 'softwareVersion',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'containerStatus', index: 'containerStatus', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'status', index: 'status',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing') return "<span class=\"txt-color-green pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";
                if (cellvalue == 'warning') return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";
                if (cellvalue == 'critical') return "<span class=\"txt-color-red pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";
                if (cellvalue == 'unknown') return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";
            }
        },
        {
            name: 'taskStatusText', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-upsql-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


function createGrid_mysql_m2(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.pager = 'pjqgridParam';
	option.caption = "";
	option.data = data['data'];
	option.colNames = ['参数名称', '默认值', '重启生效', '说明'];
	option.colModel = [
        {name: 'name', index: 'name', editable: false},
        {name: 'value', index: 'value', editable: false},
        {name: 'mustRestart', index: 'mustRestart', editable: false},
        {name: 'description', index: 'description', editable: false}
    ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridParam").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridParam").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridParam").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridParam").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridParam").jqGrid(option);
	
	$("#jqgridParam").navGrid('#pjqgridParam',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridParam").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}
function createGrid_mysql_m3(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.pager = 'pjqgridBackupStrategy';
	option.caption = "";
	option.data = data['data'];
	option.colNames = ['策略类型', '发起时间', '周期', '启用/禁用', '创建时间', '创建者','id'];
	option.colModel = [
        {name: 'typeText', index: 'typeText', editable: false},
        {name: 'cronExpression', index: 'cronExpression', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		var crons = rowObject.cronExpression.split(' ');
        		var cronText = '';
        		if(crons[2] != '*'){
        			cronText += '每月 ';
        			cronText += crons[2] + '日 ';
        		} else if(crons[4] != '*'){
        			cronText += '每周 ';
        			cronText += '周' + crons[4] + ' ';
        		} else {
        			cronText += '每日 ';
        		}
        		cronText += crons[1] + ':' + crons[0];
                return cronText;
            }
        },
        {name: 'retention', index: 'retention', editable: false},
        {name: 'enabledText', index: 'enabledText', editable: false},
        {name: 'createDateTime', index: 'createDateTime', editable: false},
        {name: 'createLoginUserName', index: 'createLoginUserName', editable: false},
        {name: 'id', index: 'id', hidden: true}
    ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridBackupStrategy").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridBackupStrategy").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridBackupStrategy").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridBackupStrategy").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridBackupStrategy").jqGrid(option);
	
	$("#jqgridBackupStrategy").navGrid('#pjqgridBackupStrategy',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridBackupStrategy").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}
function createGrid_mysql_m4(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.pager = 'pjqgridBackupList';
	option.caption = "";
	option.multiselect = false;
	option.data = data['data'];
	option.colNames = ['备份名称', '备份类型', '备份大小', '创建时间', '过期时间', '备注'];
	option.colModel = [
        {name: 'name', index: 'name', editable: false},
        {name: 'backupType', index: 'backupType', editable: false},
        {name: 'size', index: 'size', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return BytesToSize(rowObject.size);
            }
        },
        {name: 'createDateTime', index: 'createDateTime', editable: false},
        {name: 'expire', index: 'expire', editable: false},
        {name: 'remark', index: 'remark', editable: false}
    ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridBackupList").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridBackupList").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridBackupList").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridBackupList").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridBackupList").jqGrid(option);
	
	$("#jqgridBackupList").navGrid('#pjqgridBackupList',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridBackupList").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}

function createGrid_mysql_m5(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.pager = 'pjqgridRelation';
	option.caption = "";
	option.multiselect = false;
	option.data = data;
	option.colNames = ['实例名称', '角色', 'IP', '端口', '主机IP', '主机名', '状态', '容器状态'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false},
        {name: 'role', index: 'role', editable: false},
        {name: 'serverIp', index: 'serverIp', editable: false},
        {name: 'portValue', index: 'portValue', editable: false},
        {name: 'hostIp', index: 'hostIp', editable: false},
        {name: 'hostName', index: 'hostName', editable: false},
        {name: 'statusText', index: 'statusText', editable: false},
        {name: 'containerStatus', index: 'containerStatus', editable: false}
    ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridRelation").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridRelation").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridRelation").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridRelation").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridRelation").jqGrid(option);
	
	$("#jqgridRelation").navGrid('#pjqgridRelation',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridRelation").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}

function createGrid_mysql_m7(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.pager = 'pjqgridDatabase';
	option.caption = "";
	option.data = data['data'];
	option.colNames = ['库名', '编码类型'];
	option.colModel = [
        {name: 'name', index: 'name', editable: false},
        {name: 'characterSetText', index: 'characterSetText', editable: false}
    ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridDatabase").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridDatabase").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridDatabase").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridDatabase").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridDatabase").jqGrid(option);
	
	$("#jqgridDatabase").navGrid('#pjqgridDatabase',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridDatabase").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}

function createGrid_user(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '登录用户名', '用户名', '用户状态', '联系电话','邮箱', '注册时间'];
	option.colModel = [
        { name : 'username', index : 'username', editable : false},
        { name : 'name', index : 'name', editable : false },
        { name : 'enabledText', index : 'enabledText', editable : false },
        { name : 'telephone', index : 'telephone', editable : false},
        { name : 'email', index : 'email', editable : false},
        { name : 'registerDatetime', index : 'registerDatetime', editable : false}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

function createGrid_event(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '告警值', '告警名', '告警等级', '服务名','主机名', '所属集群', '创建者'];
	option.colModel = [
        { name : 'value', index : 'value', editable : false},
        { name : 'name', index : 'name', editable : false },
        { name : 'level', index : 'level', editable : false },
        { name : 'serv_name', index : 'serv_name', editable : false},
        { name : 'host_name', index : 'host_name', editable : false},
        { name : 'cluster_name', index : 'cluster_name', editable : false},
        { name : 'owner', index : 'owner', editable : false}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//新建任务列表
function createGrid_task(data){
	  $("#jqgrid").jqGrid({
        data : data,
        datatype : "local",
        height : 'auto',
        colNames : [ '所属者', '操作时间', '对象类型', '对象名称', '任务类型', '状态','回执信息','id'],
        colModel : [
            { name : 'owner', index : 'owner', editable : false },
            { name : 'time', index : 'time', editable : false },
            { name : 'type', index : 'type',  editable : false },
            { name : 'name', index : 'name', editable : false },
            { name : 'tasktype', index : 'tasktype', editable : false },
            { name : 'state', index : 'state',  editable : false },
            { name : 'return', index : 'return', editable : false },
            {name:"id",index:"id",hidden:true}
        ],

        //pager : '#pjqgrid',
        sortname : 'owner',
        toolbarfilter: true,
        viewrecords : true,
        sortorder : "asc",
        multiselect:false,//设置为false则无勾选框出现
        rownumbers: true,//设置序号
        hidegrid:false,
        editurl : "dummy.html",
        caption : "",
        autowidth : true,
        loadComplete: function () {  //隐藏滚动条
            $("#jqgrid").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
        },
        onSelectRow: function(id){
            var s;
            s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow');
            if(s.length>1){
                for(var i=0;i<=s.length;i++){
                    if(s[i]!=id){
                        $("#jqgrid").jqGrid('setSelection', s[i]);
                    }
                }
            }
        },
        onSelectAll:function(rowids,statue) {
            $("#jqgrid").jqGrid('resetSelection');
        }

    });
    $("#jqgrid").jqGrid('navGrid', "#pjqgrid", {
        edit : false,
        add : false,
        del : true
    });
    $("#jqgrid").jqGrid('inlineNav', "#pjqgrid");
    /* Add tooltips */
    $('.navtable .ui-pg-button').tooltip({
        container : 'body'
    });

    // remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    // update buttons

    $(window).on('resize.jqGrid', function () {
        $("#jqgrid").jqGrid( 'setGridWidth', $("#content").width() );
    });
}

//事件监控列表
function createGrid_monitor_info(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '事件名称', '事件等级', '事件值','实例名称','生成时间','用户名称','主机名称','集群名称'];
	option.colModel = [
      { name : 'name', index : 'name', editable : false },
      { name : 'level', index : 'level', editable : false, width:'180px' },
      { name : 'value', index : 'value', editable : false},
      { name : 'serv_name', index : 'serv_name', editable : false },
      { name : 'create_time', index : 'create_time', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
        	  return new Date(cellvalue).toLocaleString();
          }  
      },
      { name : 'owner', index : 'owner', editable : false },
      { name : 'host_name', index : 'host_name', editable : false },
      { name : 'cluster_name', index : 'cluster_name', editable : false }
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//redis服务列表
function createGrid_redis_a1(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames =  [ '站点名称','所属用户','业务系统','业务子系统','服务名称','部署架构','软件版本', '性能套餐','访问地址','服务状态','任务状态','softwareImageId','dateSize','networkBandwidth','id'];
	option.colModel = [
		{ name : 'siteName', index : 'siteName', editable : false },
		{ name : 'owner', index : 'owner', editable : false },
		{ name : 'businessSystemName', index : 'businessSystemName', editable : false },
		{ name : 'businessSubSystemName', index : 'businessSubSystemName', editable : false },
        { name : 'servName', index : 'servName', editable : false },
        { name : 'archName', index : 'archName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upredis'){
        				ret = v.archName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'softwareVersion', index : 'softwareVersion', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upredis'){
        				ret = v.softwareVersion;
        			}
        		});
        		return ret;
            }
        },
        { name : 'scaleName', index : 'scaleName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upredis'){
        				ret = v.scaleName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'endPointIps', index : 'endPointIps', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'urproxy' && v.endPointIps != undefined){
        				$.each(v.endPointIps, function(i, endPointIp){
        					ret += endPointIp +":"+v.port+ "</br>";
            			});
        			}
        		});
        		return ret;
            }
        },
        { name : 'availableStatus', index : 'availableStatus', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing'){ return "<span class=\"txt-color-green pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";}else
                if (cellvalue == 'warning'){ return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";}
                if (cellvalue == 'critical'){ return "<span class=\"txt-color-red pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";}else
                if (cellvalue == 'unknown'){ return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";}else
                	{return "";}
        	}
        },
        { name : 'taskStatusText', index : 'taskStatusText', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-service-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#serviceModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            },editable: false, align: "center"
        },
        { name : 'softwareImageId', index : 'softwareImageId', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.softwareImageId;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'dateSize', index : 'dateSize', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				ret = v.dateSize;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'networkBandwidth', index : 'networkBandwidth', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'upsql'){
        				if(v.networkBandwidth == 0){
        					ret = "无限制";
        				}else{
        					ret = v.networkBandwidth+"M";
        				}
        			}
        		});
        		return ret;
            },hidden:true
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//事件监控列表
function reloadUserGrid(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '事件名称', '事件等级', '事件值','实例名称','生成时间','用户名称','主机名称','集群名称'];
	option.colModel = [
      { name : 'name', index : 'name', editable : false },
      { name : 'level', index : 'level', editable : false, width:'180px' },
      { name : 'value', index : 'value', editable : false},
      { name : 'serv_name', index : 'serv_name', editable : false },
      { name : 'create_time', index : 'create_time', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
        	  return new Date(cellvalue).toLocaleString();
          }  
      },
      { name : 'owner', index : 'owner', editable : false },
      { name : 'host_name', index : 'host_name', editable : false },
      { name : 'cluster_name', index : 'cluster_name', editable : false }
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//系统列表
function createGrid_business_systems(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '业务系统名称', '创建时间', '所属者', '描述','id'];
	option.colModel = [
      { name : 'name', index : 'name', editable : false },
      { name : 'createDateTime', index : 'createDateTime', editable : false, width:'180px' },
      { name : 'owner', index : 'owner', editable : false},
      { name : 'description', index : 'description', editable : false},
      {name:"id",index:"id",hidden:true}
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}

//子系统列表
function createGrid_business_subsystems(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '业务系统名称','子系统名称', '创建时间', '所属者','描述', 'businessSystemId','id'];
	option.colModel = [
	  { name : 'businessSystem.name', index : 'businessSystem.name', editable : false },
      { name : 'name', index : 'name', editable : false },
      { name : 'createDateTime', index : 'createDateTime', editable : false, width:'180px' },
      { name : 'businessSystem.owner', index : 'businessSystem.owner', editable : false},
      { name : 'description', index : 'description', editable : false},
      {name:"id",index:"id",hidden:true},
      {name:"businessSystem.id",index:"businessSystem.id",hidden:true}
  ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}


//服务管理用户信息列表
function create_User_Grid(data){
	var option = {};
	var jqGrid_user_template = {
			datatype : "local",
			height : 'auto',
			sortname : 'name',
			sortorder : "asc",
			multiselect:true,
			autowidth : true,
			pager : '#pjqgridUser',
			hidegrid: false,
			rowNum: 20,
	        rowList: [10, 20, 30],
	        viewrecords: true
	}
	$.extend(true, option, jqGrid_user_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames = [ '用户名','模式', '白名单', '黑名单','数据库权限'];
	option.colModel = [
	  { name : 'username', index : 'username', editable : false },
      { name : 'modelText', index : 'modelText', editable : false },
      { name : 'whiteIps', index : 'whiteIps', editable : false },
      { name : 'blackIps', index : 'blackIps', editable : false},
      { name : 'dbPrivileges', index : 'dbPrivileges', editable : false,
    	  formatter: function (cellvalue, options, rowObject) {
    		if(cellvalue.length == 0){
      			return "";
      		} else {
      			var ret = "";
      			$.each(cellvalue, function(k, v){
      				ret += "库名:"+k+"&nbsp;&nbsp;权限:"+v+"<br/>";
      			});
      			return ret;
      		}
          } 
      }
  ];
	option.onSelectRow = function(id){
	    var s;
	    s = $("#jqgridUser").jqGrid('getGridParam', 'selarrrow');
	    if(s.length>1){
	        for(var i=0;i<=s.length;i++){
	            if(s[i]!=id){
	                $("#jqgridUser").jqGrid('setSelection', s[i]);
	            }
	        }
	    }
	};
	option.onSelectAll = function(rowids, statue) {
	    $("#jqgridUser").jqGrid('resetSelection');
	};
	option.loadComplete = function(){
		$("#jqgridUser").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
	};
	
	$("#jqgridUser").jqGrid(option);
	
	$("#jqgridUser").navGrid('#pjqgridUser',
			{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
			{}, // use default settings for edit
			{}, // use default settings for add
			{},  // delete instead that del:false we need this
			{multipleSearch : true}, // enable the advanced searching
			{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
		);
	
	// remove classes
    $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
    $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
    $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
    $(".ui-jqgrid-pager").removeClass("ui-state-default");
    $(".ui-jqgrid").removeClass("ui-widget-content");

    // add classes
    $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
    $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");


    $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
    $(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
    $(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
    $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
    $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
    $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
    $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
    $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

    $( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

    $( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

    $( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

    $( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
    $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
    

    $(window).on('resize.jqGrid', function () {
        $("#jqgridUser").jqGrid( 'setGridWidth', $("#content").width() );
    })    
}


//redis服务管理列表
function createGrid_redis(data){
	var option = {};
	var colornum = '';
	var dataArray=new Array();
	for(var i=0;i<data['data'].length;i++){
		(i%2 ==0) ?colornum = "333333":colornum = "900323";
		for(var k=0;k<data['data'][i]['units'].length;k++){
			data['data'][i]['units'][k]['fontcolor'] = colornum;
			dataArray.push(data['data'][i]['units'][k]);
		}
	}
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = dataArray;
	option.colNames = ['实例单元名称', '所属集群', '所属主机', '服务地址', '服务端口','版本号','容器状态', '运行状态','任务详情', 'id'];
	option.colModel = [
        {name: 'relateName', index: 'relateName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            },width:'200px'
        },
        {name: 'clusterName', index: 'clusterName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'hostName', index: 'hostName', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'serverIp', index: 'serverIp', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'portValue', index: 'portValue', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'softwareVersion', index: 'softwareVersion',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'containerStatus', index: 'containerStatus', editable: false,
        	formatter: function (cellvalue, options, rowObject) {
                return "<div style = 'color:#"+rowObject.fontcolor+"'>"+cellvalue+"</div>";
            }
        },
        {name: 'status', index: 'status',  editable: false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing') return "<span class=\"txt-color-green pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";
                if (cellvalue == 'warning') return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";
                if (cellvalue == 'critical') return "<span class=\"txt-color-red pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";
                if (cellvalue == 'unknown') return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 15px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";
            }
        },
        {
            name: 'taskStatusText', editable: false,
            formatter: function (cellvalue, options, rowObject) {
            	var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-upsql-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#taskModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            }
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}



//mysql服务
function createGrid_mysql_list(data){
	var option = {};
	$.extend(true, option, jqGrid_template);
	option.caption = "";
	option.data = data['data'];
	option.colNames =  [ '站点名称','所属用户','业务系统','业务子系统','服务名称','部署架构','软件版本', '性能套餐','访问地址','服务状态','任务状态','softwareImageId','dateSize','networkBandwidth','id'];
	option.colModel = [
		{ name : 'siteName', index : 'siteName', editable : false },
		{ name : 'owner', index : 'owner', editable : false },
		{ name : 'businessSystemName', index : 'businessSystemName', editable : false },
		{ name : 'businessSubSystemName', index : 'businessSubSystemName', editable : false },
        { name : 'servName', index : 'servName', editable : false },
        { name : 'archName', index : 'archName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				ret = v.archName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'softwareVersion', index : 'softwareVersion', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				ret = v.softwareVersion;
        			}
        		});
        		return ret;
            }
        },
        { name : 'scaleName', index : 'scaleName', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				ret = v.scaleName;
        			}
        		});
        		return ret;
            }
        },
        { name : 'endPointIps', index : 'endPointIps', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql' && v.endPointIps != undefined){
        				$.each(v.endPointIps, function(i, endPointIp){
        					ret += endPointIp +":"+v.port+ "</br>";
            			});
        			}
        		});
        		return ret;
            }
        },
        { name : 'availableStatus', index : 'availableStatus', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		if (cellvalue == 'passing'){ return "<span class=\"txt-color-green pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-check-circle\"></i></span>";}else
                if (cellvalue == 'warning'){ return "<span class=\"txt-color-yellow pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-exclamation-circle\"></i></span>";}
                if (cellvalue == 'critical'){ return "<span class=\"txt-color-red pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-times-circle\"></i></span>";}else
                if (cellvalue == 'unknown'){ return "<span class=\"txt-color-blue pull-left\" style=\"font-size: 16px;margin-left: 40%;\"><i class=\"fa fa-lg fa-question-circle\"></i></span>";}else
                	{return "";}
        	}
        },
        { name : 'taskStatusText', index : 'taskStatusText', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var con = cellvalue != null?cellvalue:'';
                return "<a href=\"\" data-service-id='"+rowObject.id+"'\" data-toggle=\"modal\" data-target=\"#serviceModal\"><span class=\" pull-left\">"+con+"&nbsp;<i class=\"fa fa-lg fa-book\"></i></span></a>";
            },editable: false, align: "center"
        },
        { name : 'softwareImageId', index : 'softwareImageId', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				ret = v.softwareImageId;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'dateSize', index : 'dateSize', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				ret = v.dateSize;
        			}
        		});
        		return ret;
            },hidden:true
        },
        { name : 'networkBandwidth', index : 'networkBandwidth', editable : false,
        	formatter: function (cellvalue, options, rowObject) {
        		var ret = "";
        		$.each(rowObject.subServs, function(k, v){
        			if(v.type == 'mysql'){
        				if(v.networkBandwidth == 0){
        					ret = "无限制";
        				}else{
        					ret = v.networkBandwidth+"M";
        				}
        			}
        		});
        		return ret;
            },hidden:true
        },
        {name:"id",index:"id",hidden:true}
    ];
	option.onSelectRow = jqGrid_OnSelectRow;
	option.onSelectAll = jqGrid_OnSelectAll;
	option.loadComplete = jqGrid_LoadComplete;
	
	$("#jqgrid").jqGrid(option);
	
	jqGrid_ResetClass();
}




//慢日志列表
function createGrid_slowlog(data){
	
	$("#size").text("size : "+data['data']['size']);
	$("#querySum").text("querySum : "+data['data']['querySum']);
	$("#uniqueQuerySum").text("uniqueQuerySum : "+data['data']['uniqueQuerySum']);
	
        var option = {};
		var jqGrid_user_template = {
				datatype : "local",
				height : 'auto',
				sortname : 'name',
				sortorder : "asc",
				multiselect:false,
				autowidth : true,
				pager : '#pjqgridslowlog',
				hidegrid: false,
				rowNum: 20,
		        rowList: [10, 20, 30],
		        viewrecords: true
		}
		$.extend(true, option, jqGrid_user_template);
		option.caption = "";
		option.data = data['data']['slowLogDetails'];
		option.colNames = [ 'checkSum', 'total', 'avg', 'max', 'min', 'count','querySql','databse','host','user','lastSceen','firstSceen'];
		option.colModel = [
            { name : 'checkSum', index : 'checkSum', editable : false,width:'220px' },
            { name : 'total', index : 'total', editable : false },
            { name : 'avg', index : 'avg',  editable : false },
            { name : 'max', index : 'max', editable : false },
            { name : 'min', index : 'min', editable : false },
            { name : 'count', index : 'count',  editable : false },
            { name : 'querySql', index : 'querySql', editable : false ,width:'400px'},
            { name : 'databse', index : 'databse', editable : false },
            { name : 'host', index : 'host', editable : false },
            { name : 'user', index : 'user', editable : false },
            { name : 'lastSceen', index : 'lastSceen', editable : false },
            { name : 'firstSceen', index : 'firstSceen', editable : false }
        ];
		option.onSelectRow = function(id){
		    var s;
		    s = $("#jqgridslowlog").jqGrid('getGridParam', 'selarrrow');
		    if(s.length>1){
		        for(var i=0;i<=s.length;i++){
		            if(s[i]!=id){
		                $("#jqgridslowlog").jqGrid('setSelection', s[i]);
		            }
		        }
		    }
		};
		option.onSelectAll = function(rowids, statue) {
		    $("#jqgridslowlog").jqGrid('resetSelection');
		};
		option.loadComplete = function(){
			$("#jqgridslowlog").closest(".ui-jqgrid-bdiv").css({ 'overflow-y' : 'hidden','overflow-x':'hidden' });
		};
		
		$("#jqgridslowlog").jqGrid(option);
		
		$("#jqgridslowlog").navGrid('#pjqgridslowlog',
				{add:false, edit:false, view:false, del:false, refresh:false, search:true}, 
				{}, // use default settings for edit
				{}, // use default settings for add
				{},  // delete instead that del:false we need this
				{multipleSearch : true}, // enable the advanced searching
				{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
			);
		
		// remove classes
		$(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
		$(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
		$(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
		$(".ui-jqgrid-pager").removeClass("ui-state-default");
		$(".ui-jqgrid").removeClass("ui-widget-content");
		
		// add classes
		$(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
		$(".ui-jqgrid-btable").addClass("table table-bordered table-striped");
		
		
		$(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
		$(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
		$(".ui-icon.ui-icon-pencil").removeClass().addClass("fa fa-pencil");
		$(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
		$(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
		$(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
		$(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
		$(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");
		
		$( ".ui-icon.ui-icon-seek-prev" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
		$(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");
		
		$( ".ui-icon.ui-icon-seek-first" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
		$(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");
		
		$( ".ui-icon.ui-icon-seek-next" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
		$(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");
		
		$( ".ui-icon.ui-icon-seek-end" ).wrap( "<div class='btn btn-sm btn-default'></div>" );
		$(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");
		
		
		$(window).on('resize.jqGrid', function () {
		    $("#jqgridslowlog").jqGrid( 'setGridWidth', $("#content").width() );
		})    

}